﻿<BadHabit_Factory_Controls:GenericPanel
    x:Class="BadHabit.Factory.Controls.PaymentPanel"
    x:Name="paymentPanel"
    
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:BadHabit_Factory_Controls="clr-namespace:BadHabit.Factory.Controls"        
    xmlns:BadHabit_WPFTools="clr-namespace:BadHabit.WPFTools;assembly=BadHabit.WPFTools"       
    xmlns:Microsoft_Toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
    
    xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
    
    xmlns:props="clr-namespace:BadHabit.Factory.Windows.Properties"
    
    
    DataContextChanged="paymentPanel_DataContextChanged"
    
    HorizontalAlignment="Stretch"
    VerticalAlignment="Stretch"
    Background="Transparent">

    <BadHabit_Factory_Controls:GenericPanel.CommandBindings>        
        <CommandBinding Command="ApplicationCommands.Save" CanExecute="Save_CanExecute" Executed="Save_Executed"/>
    </BadHabit_Factory_Controls:GenericPanel.CommandBindings>



    <BadHabit_Factory_Controls:GenericPanel.Resources>

        <CollectionViewSource x:Key="PaymentList" Source="{Binding ProjectPayment}">            
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="PlannedPayDate" Direction="Ascending"  />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

    </BadHabit_Factory_Controls:GenericPanel.Resources>
    
    
    
    <Grid x:Name="ContentPanel" VerticalAlignment="Stretch">
        
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <DockPanel Grid.Row="0">
            <ToolBar x:Name="Toolbar" DockPanel.Dock="Left" ToolBarTray.IsLocked="True" Height="60" >


                <StackPanel Margin="5,0,5,0" HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock Text="{Binding ElementName=paymentPanel, Path=TotalPrice, StringFormat='{}{0:C}'}"  Style="{StaticResource ToolBarBigTextBlock}" />
                <TextBlock Text="{x:Static props:Resources.price}"  Style="{StaticResource ToolBarBigTextBlock}"  FontSize="12" />
            </StackPanel>
            
            <StackPanel Margin="5,0,5,0" HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock Text="{Binding ElementName=paymentPanel, Path=StillToPay, StringFormat='{}{0:C}'}"  Style="{StaticResource ToolBarBigTextBlock}" />
                <TextBlock Text="{x:Static props:Resources.still_to_pay}"  Style="{StaticResource ToolBarBigTextBlock}"  FontSize="12" />
            </StackPanel>
            
            <StackPanel Margin="5,0,5,0" HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock Text="{Binding ElementName=paymentPanel, Path=InDebt, StringFormat='{}{0:C}'}"  Style="{StaticResource ToolBarBigTextBlock}" Foreground="{StaticResource AlertValueBrush}"/>
                <TextBlock Text="{x:Static props:Resources.in_debit}"  Style="{StaticResource ToolBarBigTextBlock}"  FontSize="12" Foreground="{StaticResource AlertValueBrush}" />
                <StackPanel.Style>
                    <Style>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=paymentPanel, Path=IsInDebt}" Value="False">
                                <Setter Property="StackPanel.Visibility" Value="Collapsed"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </StackPanel.Style>
            </StackPanel>


            </ToolBar>
            <Button
                        x:Name="commitButton"
                        DockPanel.Dock="Right"
                        Style="{StaticResource CommitButton}"
                        Command="ApplicationCommands.Save"
                        HorizontalAlignment="Right" 
                        Margin="5" />
        </DockPanel>

        <Border             
                Grid.Row="1">

            <TextBlock  VerticalAlignment="Top" TextWrapping="Wrap"
                           Text="{x:Static props:Resources.Can_not_add_payments_because_project_does_not_have_proposal}"/>

            <Border.Style>
                <Style BasedOn="{StaticResource AlertBorder}" TargetType="Border" >
                    <Setter Property="Border.Visibility" Value="Collapsed"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Proposal.Count}" Value="0">
                            <Setter Property="Border.Visibility" Value="Visible"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
        </Border>

        <Border
                Grid.Row="2"                
                Style="{StaticResource RoundBorder}">

            <BadHabit_WPFTools:DataGrid
                x:Name="paymentDataGrid"
                
                BadHabit_WPFTools:RoleChecker.RequiredEnableRole="SCRUM_MASTER"
                
                UseNavigationExtensions="True"
                
                AutoGenerateColumns="False"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                
                Margin="2,2,2,2"                
                GridLinesVisibility="Horizontal"
                VerticalGridLinesBrush="{StaticResource WaterMarkBrush}"
                HorizontalGridLinesBrush="{StaticResource WaterMarkBrush}"
                RowHeaderWidth="0"
                Background="White"
                BorderThickness="0,0,0,0"                                
                SelectionMode="Single"
                SelectionUnit="FullRow"
              
                
                InitializingNewItem="paymentDataGrid_InitializingNewItem"
                
                AllowDrop="False"
               
                
                
             
                CanUserDeleteRows="True"                
                CanUserSortColumns="True"
                CanUserReorderColumns="False"
        
                RowEditEnding="paymentDataGrid_RowEditEnding"
            
                ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                
                <Microsoft_Toolkit:DataGrid.Style>
                    <Style TargetType="Microsoft_Toolkit:DataGrid" BasedOn="{StaticResource {x:Type Microsoft_Toolkit:DataGrid}}">                        
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Proposal.Count}" Value="0">
                                <Setter Property="CanUserAddRows" Value="False"/>
                            </DataTrigger>
                        </Style.Triggers>                        
                    </Style>
                </Microsoft_Toolkit:DataGrid.Style>
                
                <Microsoft_Toolkit:DataGrid.Columns>


                    <Microsoft_Toolkit:DataGridTemplateColumn
                        IsReadOnly="True"
                        >
                        <Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Image Source="/Images/Icons/money.png" Stretch="Uniform" Width="16" Height="16" />
                            </DataTemplate>
                        </Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                    </Microsoft_Toolkit:DataGridTemplateColumn>

                    <Microsoft_Toolkit:DataGridTemplateColumn                                         
                        Header="{x:Static props:Resources.Proposal}"
                        CanUserResize="False"                        
                        MinWidth="150"
                        Width="Auto">
                        <Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <BadHabit_WPFTools:ComboBox                                 
                                    DropDownBackground="White"                                                                                                            
                                    SelectedValue="{Binding ProposalUId}"                            
                                    DisplayMemberPath="ProposalName"
                                    SelectedValuePath="ProposalUId" 
                                    HorizontalAlignment="Stretch"
                                    ItemsSource="{Binding Source={StaticResource ProposalList}}"/>
                            </DataTemplate>
                        </Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                    </Microsoft_Toolkit:DataGridTemplateColumn>

                    <Microsoft_Toolkit:DataGridTextColumn                                                
                        CanUserResize="False"                        
                        Header="{x:Static props:Resources.Value}"                                                
                        Binding="{Binding Value, StringFormat='{}{0:C}'}"                        
                        CellStyle="{StaticResource RightAlignCellStyle}"
                        HeaderStyle="{StaticResource RightAlignColumnStyle}"
                        Width="200"/>

                    <Microsoft_Toolkit:DataGridTextColumn
                        Header="{x:Static props:Resources.Payed_Value}"                        
                        CanUserResize="False" 
                        Width="200"                        
                        CellStyle="{StaticResource RightAlignCellStyle}"       
                        HeaderStyle="{StaticResource RightAlignColumnStyle}"
                        Binding="{Binding PayedValue, StringFormat='{}{0:C}'}"/>


                    <Microsoft_Toolkit:DataGridTemplateColumn                        
                        Header="{x:Static props:Resources.Expires_at}"       
                        CanUserResize="False" 
                        SortMemberPath="PlannedPayDate"
                        CellStyle="{StaticResource RightAlignCellStyle}"
                        HeaderStyle="{StaticResource RightAlignColumnStyle}">
                        <Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Microsoft_Toolkit:DatePicker SelectedDate="{Binding PlannedPayDate}" Style="{StaticResource DataGridDatePicker}"/>
                            </DataTemplate>
                        </Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                    </Microsoft_Toolkit:DataGridTemplateColumn>

                    <Microsoft_Toolkit:DataGridTextColumn
                        Header="{x:Static props:Resources.Invoice_Number}"                        
                        CanUserResize="False" 
                        Width="*"               
                        Binding="{Binding InvoiceNumber}">
                        <Microsoft_Toolkit:DataGridTextColumn.EditingElementStyle>
                            <Style TargetType="TextBox" BasedOn="{StaticResource TransparentEditingElementStyle}">
                                <Setter Property="MaxLength" Value="50"/>
                            </Style>
                        </Microsoft_Toolkit:DataGridTextColumn.EditingElementStyle>
                    </Microsoft_Toolkit:DataGridTextColumn>


                    <Microsoft_Toolkit:DataGridTemplateColumn                        
                        Header="{x:Static props:Resources.Invoice_Date}"       
                        CanUserResize="False" 
                        SortMemberPath="InVoiceDate"
                        CellStyle="{StaticResource RightAlignCellStyle}"
                        HeaderStyle="{StaticResource RightAlignColumnStyle}">
                        <Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Microsoft_Toolkit:DatePicker SelectedDate="{Binding InVoiceDate}" Style="{StaticResource DataGridDatePicker}"/>
                            </DataTemplate>
                        </Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                    </Microsoft_Toolkit:DataGridTemplateColumn>

                    

                    <Microsoft_Toolkit:DataGridTemplateColumn                        
                        Header="{x:Static props:Resources.Payed_at}"       
                        CanUserResize="False" 
                        SortMemberPath="PayedDate"
                        CellStyle="{StaticResource RightAlignCellStyle}"
                        HeaderStyle="{StaticResource RightAlignColumnStyle}">
                        <Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Microsoft_Toolkit:DatePicker SelectedDate="{Binding PayedDate}" Style="{StaticResource DataGridDatePicker}"/>
                            </DataTemplate>
                        </Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                    </Microsoft_Toolkit:DataGridTemplateColumn>


                    
                </Microsoft_Toolkit:DataGrid.Columns>

            </BadHabit_WPFTools:DataGrid>




        </Border>

    </Grid>
</BadHabit_Factory_Controls:GenericPanel>
